package com.majun.web;

import com.alibaba.fastjson2.JSONObject;
import com.majun.bean.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@CrossOrigin(origins = "http://localhost:8080", maxAge = 3600)
@RestController
@RequestMapping("/log")
public class LogFilterController {

    private static final Logger log = LoggerFactory.getLogger(LogFilterController.class);

    @GetMapping("/get")
    public void get(String msg) {

        System.err.println(msg);
        //计时器
        StopWatch stopWatch = new StopWatch();
        // 开始时间
        stopWatch.start();
        // TODO 业务执行时间
        // 结束时间
        stopWatch.stop();
        // 统计执行时间（毫秒）
//        System.out.println("执行时长：" + stopWatch.getTime(TimeUnit.MILLISECONDS) + " 毫秒.");
    }

    @PostMapping("/post")
    public void post(String msg) {
        System.err.println(msg);
        //计时器
        StopWatch stopWatch = new StopWatch();
        // 开始时间
        stopWatch.start();
        // TODO 业务执行时间
        // 结束时间
        stopWatch.stop();
        // 统计执行时间（毫秒）
//        System.out.println("执行时长：" + stopWatch.getTime(TimeUnit.MILLISECONDS) + " 毫秒.");
    }

    @PostMapping("/json")
    public String json(@RequestBody User user){
//        int i = 1/0;
        log.error(JSONObject.toJSONString(user));
        return "新增订单成功";
    }

    @GetMapping("/path/{name}")
    public String path(@PathVariable String name){
//        System.err.println(name);
        log.info("path === name:[{}]", name);
        return name;
    }

    @PostMapping("/list")
    public String list(@RequestBody List<String> msgs){
//        int i = 1/0;
        log.error(JSONObject.toJSONString(msgs));
        return "新增订单成功";
    }

//    @CrossOrigin("http://localhost:8080")
    @GetMapping("/getdata")
    public String get() {
//        System.err.println(msg);
        //计时器
        StopWatch stopWatch = new StopWatch();
        // 开始时间
        stopWatch.start();
        // TODO 业务执行时间
        // 结束时间
        stopWatch.stop();
        // 统计执行时间（毫秒）
//        System.out.println("执行时长：" + stopWatch.getTime(TimeUnit.MILLISECONDS) + " 毫秒.");
        return "test";
    }

}